package com.my.twitterSample;

import android.app.Activity;
import android.os.Bundle;
import android.sax.TextElementListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import twitter4j.Twitter;
import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.User;

public class twitterSample extends Activity {
    /** Called when the activity is first created. */
	private EditText mUsername;
	private EditText mPassword;
	private EditText mMessage;
	private Button mSendButton;
	private Button mReceiveButton;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mUsername = (EditText)findViewById(R.id.EditText01);
        mPassword = (EditText)findViewById(R.id.EditText02);
        mMessage = (EditText)findViewById(R.id.EditText03);
        mSendButton = (Button)findViewById(R.id.Button01);
        mReceiveButton = (Button)findViewById(R.id.Button02);
        
        final String _mUsername = mUsername.getText().toString();
        final String _mPassword = mPassword.getText().toString();
        final String _mMessage = mMessage.getText().toString();
        
        mSendButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
		        if(_mUsername.equals("") || _mPassword.equals("") || _mMessage.equals(""))
		        	Toast.makeText(getApplicationContext(), "Input the User Information", Toast.LENGTH_LONG).show();
		        
		        else {
		        	Twitter twitter = new Twitter(_mUsername, _mPassword);
		            
		            Status status;
		            
		            try {
		    			status = twitter.updateStatus(_mMessage);
		    			Toast.makeText(getApplicationContext(), "Successfully updated the status to [" + status.getText() + "]." , Toast.LENGTH_LONG).show();
		    		} catch (TwitterException e) {
		    			// TODO Auto-generated catch block
		    			Toast.makeText(getApplicationContext(), "Successfully updated the status to [" + e + "]." , Toast.LENGTH_LONG).show();
		    		}
		        }
				
			}
		});
    }
}